package gjtx4;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapCompany {
    private String companyName;
    private String site;
    private String phone;
    private String manage;
    private String number;
    Staff1 st = new Staff1();
    Map<String, Staff1> map = new HashMap<>();

    public MapCompany(String companyName, String site, String phone, String manage) {
        this.companyName = companyName;
        this.site = site;
        this.phone = phone;
        this.manage = manage;
    }

    public MapCompany() {
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getManage() {
        return manage;
    }

    public void setManage(String manage) {
        this.manage = manage;
    }


    public void show() {
        System.out.println("公司:" + companyName + "地址在" + site);
    }

    //招聘员工（要求工号不能重复）(在员工类中重写equals方法！！！)
    public boolean recruit(String name, int nianL, String xingB, String zhiW, int xinShui, String number) {
        st = new Staff1(name, nianL, xingB, zhiW, xinShui);
        Iterator<String> ir = map.keySet().iterator();
        while (ir.hasNext()) {
            String nm = ir.next();
            if (nm.equals(number))
                return false;
        }
        map.put(number, st);
        System.out.println("已招聘！ ");
        return true;
    }

    // 输出员工信息
    public void output() {
        System.out.println("员工信息如下：");
        Set<Map.Entry<String, Staff1>> entries = map.entrySet();
        Iterator<Map.Entry<String, Staff1>> ir = entries.iterator();
        while (ir.hasNext()) {
            Map.Entry<String, Staff1> next = ir.next();
            String k = next.getKey();
            Staff1 v = next.getValue();
            System.out.println(v + "  " + k);
        }
    }

    //辞退员工
    public boolean delete(String number) {
        if (map.containsKey(number)) {
            Iterator<String> ir = map.keySet().iterator();
            while (ir.hasNext()) {
                String k = ir.next();
                Staff1 v = map.get(k);
                if (number.equals(k)) {
                    map.remove(k, v);
                    System.out.println("已辞退！");
                    return true;
                }
            }
        }
        System.out.println("未找到！");
        return false;
    }

    public void statistics() {
        System.out.println("总共有" + map.size() + "人。");
    }

    public Staff1 salary() {
        if (map.size() > 0) {
            Set<Map.Entry<String, Staff1>> entries = map.entrySet();
            Iterator<Map.Entry<String, Staff1>> ir = entries.iterator();
            Map.Entry<String, Staff1> next = ir.next();
            String k = next.getKey();
            Staff1 v = next.getValue();
            System.out.println(v + "  " + k);
        }
        System.out.println("未找到！");
        return null;
    }
}

